package jfilters.filters.composite;

/*
    Copyright Janne Liljeblad 2008.

    This file is part of JFilters.

    JFilters is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    JFilters is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with JFilters.  If not, see <http://www.gnu.org/licenses/>.
*/

import jfilters.filters.JFilter;

public abstract class JFCompositeFilter extends JFilter
{
	//--- 0 - 255, is source opacity
	protected int opacity = 255;
	//--- source rgba
	protected int sr, sg, sb, sa;
	//--- destination rgba
	protected int dr, dg, db, da;
	//--- destination opacity 
	protected int aD = 0;


	//--- 0 - 255
	public void setSourceOpacity( int opacity ){ this.opacity = opacity; }
	//--- 0.0 - 1.0
	public void setSourceOpacity( float fopacity ){ opacity =(int)(255.0 * fopacity); }
	//--- using this works when:
	//--- - blending result is in sr, sg, sb
	//--- - destination is read into dr, dg, db.
	//--- result will go into dr, dg, db
	protected void doSourceOpacity()
	{
		aD = 255 - opacity;
		dr = sr * opacity / 255 + dr * aD / 255;
		dg = sg * opacity / 255 + dg * aD / 255;
		db = sb * opacity / 255 + db * aD / 255;
	}

}//end class